home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’93 / Don's Hacks / TSMHelper Source / TSMHelper.a next >
Encoding:
Text File  |  1993-06-18  |  5.7 KB  |  233 lines  |  [TEXT/MPS ]

  1. ;----------------------------------------------------------------
  2. ;
  3. ;  TSMHelper.a
  4. ;    ©1993 CE Software - All Rights Reserved
  5. ;    Written by Donald Brown
  6. ;
  7. ;    A small utility to properly catch clicks over TSM windows.
  8. ;
  9. ;-----------------------------------------------------------------
  10.             BLANKS        ON
  11.             STRING        ASIS
  12.             PRINT    OFF
  13.             INCLUDE 'QuickEqu.a'
  14.             INCLUDE 'ToolEqu.a'
  15.             INCLUDE 'SysEqu.a'
  16.             INCLUDE 'Traps.a'
  17.             PRINT    ON
  18.  
  19. HelperStuff        main    export
  20. ;
  21. ; Procedure Install; external;
  22. ;   installs the patches in system heap
  23. ;
  24. ;
  25. ; MyGetOSEvent - replaces GetOSEvent.  Checks to see if the event is a mousedown over our windows
  26. ;
  27. InitEntry    BRA    Install
  28.  
  29. StartofInit
  30.  
  31. MyGetOSEvent
  32.         movem.l    D1/D4/A0/A1/A2,-(SP)
  33.         move.l    A0,A2            ;save the pointer to the event
  34.         
  35.         move.L    OldGetOSEvent,A1    ;call the real GetOSEvent
  36.         jsr    (A1)
  37.         move.l    D0,D4            ;save the result for later
  38.         move.w    evtNum(A2),D0
  39.         cmp.w    #mButDwnEvt,D0
  40.         bne.s    @DontFiddle        ;See if it's a mousedown
  41.         
  42.         lea    TheHandlers,A3        ;go through our list of handlers, see if we've got any windows to check
  43.         moveq    #9,D7
  44. @HandlerLoop
  45.         tst.l    (A3)            ;is there a pointer to a windowpointer?
  46.         beq.s    @NextHandler
  47.         move.l    (A3),A0            ;is there a window there?
  48.         tst.l    (A0)
  49.         beq.s    @NextHandler
  50.         
  51.         clr.w    -(SP)            ;call FindService Window
  52.         move.l    evtMouse(A2),-(SP)    ; to see if it's a service window
  53.         pea    MyTempWindow
  54.         move.w    #$17,D0            ;this is how we call FindServiceWindow
  55.         dc.w    $AA54
  56.         move.w    (SP)+,D0
  57.         cmp.w    #3,D0            ;did we get something in a service window?
  58.         blt.s    @DontFiddle
  59.         
  60.         lea    LastMouse,A0        ;yup, save this point but don't let the system know
  61.         move.l    evtMouse(A2),(A0)
  62.         clr.w    evtNum(A2)
  63.         moveq.l    #-1,D4            ;and say it's a "null" event
  64.         bra.s    @DontFiddle        ;and branch out of the loop
  65.  
  66. @NextHandler
  67.         adda.l    #8,A3            ;try next
  68.         dbra    D7,@HandlerLoop
  69.     
  70. @DontFiddle    move.l    D4,D0        ;return to sender
  71.         movem.l    (SP)+,D1/D4/A0/A1/A2
  72.         tst.b    D0
  73.         rts
  74. ;
  75. ; GNE Filter.  Calls our routines, also makes mousedowns where appropriate
  76. ;
  77. MyGNEFilter
  78.         movem.l    A1-A4/D6-D7,-(SP)
  79.         move.l    A1,A4            ;temporarily keep pointer to event in A4
  80.         move.l    D0,D7
  81.         
  82.         move.w    evtNum(A4),D0
  83.         tst.w    D0            ;is it a null event?
  84.         beq.s    @ChangeMe
  85.         cmpi.w    #updatEvt,D0
  86.         bne.s    @DontChangeMe
  87. @ChangeMe
  88.         lea    LastMouse,A0        ;do we have a mouse?
  89.         tst.l    (A0)
  90.         beq.s    @DontChangeMe        ;if not, never mind
  91.         move.l    (A0),evtMouse(A4)    ;yup, turn this into that mousedown
  92.         move.w    #mButDwnEvt,evtNum(A4)
  93.         clr.l    (A0)            ;(and don't do it again!)
  94.         
  95. @DontChangeMe
  96.         lea    TheHandlers,A3        ;go through our list of handlers
  97.         moveq    #9,D7
  98. @HandlerLoop
  99.         tst.l    (A3)            ;is there a pointer to a windowpointer?
  100.         beq.s    @NextHandler
  101.         move.l    (A3),A0            ;is there a window there?
  102.         tst.l    (A0)
  103.         beq.s    @NextHandler
  104.         clr.w    -(SP)
  105.         move.w    D6,-(SP)
  106.         move.l    A4,-(SP)
  107.         move.l    4(A3),A0        ;call this handler
  108.         jsr    (A0)            ;syntax is Function MyHandler(oldresult:integer; VAR theevent:eventrecord):integer;
  109.         move.w    (SP)+,D6
  110. @NextHandler
  111.         adda.l    #8,A3            ;try next
  112.         dbra    D7,@HandlerLoop
  113.         
  114.         move.l    D6,D0            ;get our "result" back into D0
  115.         movem.l    (SP)+,A1-A4/D6-D7
  116.         move.w    D0,4(SP)
  117.         move.l    OldGNEFilter, A0
  118.         jmp    (A0)
  119. ;
  120. ; Procedure InstallOne(VAR wp:WindowPtr; whereproc:procptr; DoInstall:integer);
  121. ;    DoInstall=0 for remove, non-zero to add
  122. ;
  123. InstallOne
  124.         link    A6,#0
  125.         movem.l    A3/D5-D7,-(SP)
  126.         tst.w    8(A6)            ;are we installing?
  127.         bne.s    @DoAdd
  128.         lea    TheHandlers,A3        ;go through our list of handlers
  129.         moveq    #9,D7
  130. @RemoveLoop
  131.         move.l    (A3),D0            ;see if this is our windowpointer
  132.         sub.l    14(A6),D0        ;(compare the windowpointers)
  133.         _StripAddress
  134.         tst.l    D0
  135.         bne.s    @NextRemove
  136.         clr.l    (A3)            ;got it, wipe it out, we're done!
  137.         clr.l    4(A3)
  138.         bra.s    @AllDone
  139. @NextRemove
  140.         adda.l    #8,A3            ;try next
  141.         dbra    D7,@RemoveLoop
  142.         bra.s    @AllDone
  143.  
  144. @DoAdd
  145.         lea    TheHandlers,A3        ;go through our list of handlers
  146.         moveq    #9,D7
  147. @AddLoop
  148.         tst.l    (A3)
  149.         bne.s    @NextAdd        ;is this an empty spot?
  150.         move.l    14(A6),(A3)        ;yup, copy us in
  151.         move.l    10(A6),4(A3)
  152.         bra.s    @AllDone
  153. @NextAdd
  154.         adda.l    #8,A3            ;try next
  155.         dbra    D7,@AddLoop
  156.  
  157. @AllDone        
  158.         movem.l    (SP)+,A3/D5-D7
  159.         unlk    a6
  160.         move.l    (SP)+,A0
  161.         adda.l    #10,SP
  162.         jmp    (A0)
  163. ;
  164. ; The routine Gestalt will call to tell where my install routine is is
  165. ;
  166. ReturnRegister
  167.         link    A6,#0
  168.         move.l    8(A6),A0    ;return the proper response
  169.         lea    InstallOne,A1
  170.         move.l    A1,(A0)
  171.         clr.w    16(A6)
  172.         unlk    A6
  173.         move.l    (SP)+,A0
  174.         adda.l    #8,SP
  175.         jmp    (A0)
  176.  
  177.  
  178. OldGetOSEvent    dc.L    0        ;address of real GetOSEvent
  179. OldGNEFilter    dc.l    0        ;address of prior GNEFilter
  180. ;
  181. MyTempWindow    dc.l    0        ;just used to call FindServiceWindow
  182. ;
  183. storage
  184. LastMouse    dc.l    0        ;last mouse clicked, waiting for us to handle it
  185. TheHandlers    dcb.b    80,0        ;The registered TSM handlers
  186.                     ;    array[1..10] of Record wp:WindowHandle; proc:procptr end;
  187. ;
  188. Install        link    A6,#-128
  189.         movem.l    D0-D1/A0-A4,-(SP)
  190.         btst    #0,KeyMap+7    ;see if shift key's down
  191.         bne.s    @999        ;if so, don't install
  192. ;
  193. ; Check on our gestalt being there!
  194. ;
  195.         move.l    #'tsmH',D0    ;call gestalt with our connection
  196.         _Gestalt
  197.         tst.w    D0
  198.         beq.s    @999        ;if no error, we're already installed somewhere else
  199.         
  200.         move.W    #$31,D0            ;First, save old loc of GetOSEvent
  201.         _GetTrapAddress    ,NEWOS
  202.         LEA    OldGetOSEvent,A1
  203.         move.L    A0,(A1)
  204.         
  205.         LEA    OldGNEFilter,A1        ;Next, save position of GNE filter (to hook us in)
  206.         move.L    jGNEFilter,(A1)
  207.         
  208.         move.L    #Install-StartofInit,D0
  209.         _NewPtr    ,SYS        ;get a block in the system heap
  210.         move.L    A0,A4        ;save the pointer
  211.         move.L    A0,A1        ;copy stuff over
  212.         LEA    StartofInit,A0
  213.         move.L    #Install-StartofInit,D0
  214.         _BlockMove
  215.         
  216.         LEA    MyGNEFilter-StartofInit(A4),A0    ;hook into GNEFilter
  217.         move.l    A0,jGNEFilter
  218.         
  219.         move.w    #$31,D0                ;and patch GetOSEvent
  220.         LEA    MyGetOSEvent-StartofInit(A4),A0
  221.         _SetTrapAddress    ,NEWOS
  222.         
  223.         move.l    #'tsmH',D0            ;register us so others can find us
  224.         LEA    ReturnRegister-StartofInit(A4),A0
  225.         _NewGestalt
  226. @998        
  227.             
  228. @999        movem.l    (SP)+,D0-D1/A0-A4
  229.         unlk    A6
  230.         RTS
  231.  
  232.         end
  233.